﻿@model FieldControlViewModel
@{ 
	string baseUrl = Utility.GetBasePath() + Utility.UploadDirPath();
	string imgUrl = string.Empty;
	if (!string.IsNullOrEmpty(Model.FieldValue))
	{
		imgUrl = baseUrl + Model.FieldValue;
	}
	string dataVal = string.Empty;
	string dataValMsg = string.Empty;
	if (Model.EnableNull)
	{
		dataVal += " data-val-required=\"不能为空\" ";
	}
	if (!string.IsNullOrEmpty(dataVal))
	{
		dataVal += " data-val=\"true\" ";
		dataValMsg = " data-valmsg-for=\"" + Model.Prefix + Model.FieldName + "\" data-valmsg-replace=\"true\"";
	}
}
<span class="layui-col-xs9 layui-col-sm9 layui-col-md9">
	<input type="text" class="layui-input" name="@{@Model.Prefix@Model.FieldName}QRCodeText" id="@{@Model.Prefix@Model.FieldName}QRCodeText" value="" />
</span>
<span class="layui-col-xs3 layui-col-sm3 layui-col-md3 layui-input-company">
	<button class="layui-btn layui-btn-sm layuiadmin-btn-list" type="button" onclick="@{@Model.Prefix@Model.FieldName}QRCodeCreate()">生成二维码</button>
</span>
<span class="layui-col-xs12 layui-col-sm12 layui-col-md12" style="text-align:center;">
	<img id="@{@Model.Prefix@Model.FieldName}QRCodeImg" name="@{@Model.Prefix@Model.FieldName}QRCodeImg" src="@imgUrl" alt="" />
	<input type="hidden" name="@{@Model.Prefix@Model.FieldName}" id="@{@Model.Prefix@Model.FieldName}" value="@Model.FieldValue" @Html.Raw(dataVal) />
</span>
<span class="layui-bg-green">@Model.Description</span>
<span style="color:red;" @Html.Raw(dataValMsg)></span>
<script type="text/javascript">
	function @{@Model.Prefix@Model.FieldName}QRCodeCreate() {
		var QRCodeText = $("#@{@Model.Prefix@Model.FieldName}QRCodeText").val();
		if (QRCodeText == "") {
			layer.msg("生成内容不能为空");
			return false;
		}
		var url = '/Common/CreateQRCode';
		$.ajax({
			type: "POST",
			async: true,
			url: url,
			data: { "QRCodeText": QRCodeText },
			headers: {
				"X-CSRF-TOKEN-JXWebHost": $("input[name='AntiforgeryFieldname']").val()
			},
			error: function (data, status, e) {
				return false;
			},
			success: function (returnData) {
				if (returnData.Status == 1) {
					$("#@{@Model.Prefix@Model.FieldName}QRCodeImg").attr("src", "@baseUrl" + returnData.Data);
					$("#@{@Model.Prefix@Model.FieldName}").val(returnData.Data);
				}
				layer.msg(returnData.Msg);
			}
		});
	}

</script>